package com.tlgen.controller.assist;

import com.tlgen.model.Repair;
import com.tlgen.model.RespBean;
import com.tlgen.model.RespPageBean;
import com.tlgen.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: tlgen
 * @Discription:
 */
@RestController
@RequestMapping("/assist/repair")
public class RepairController {

    @Autowired
    RepairService repairService;

    @GetMapping("/")
    public RespPageBean getRepairByPage(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer size,
                                          Repair repair) {
        return repairService.getRepairByPage(page, size, repair);
    }

    @PostMapping("/")
    public RespBean addRepair(@RequestBody Repair repair) {
        if (repairService.addRepair(repair) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteRepairByEid(@PathVariable Integer id) {
        if (repairService.deleteRepairById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @PutMapping("/")
    public RespBean updateRepair(@RequestBody Repair repair) {
        if (repairService.updateRepair(repair) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }
}
